#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
//	system("start https://www.lanqiao.cn/problems/4437/learning/");

	int n;
	cin >> n;
	vector<int> a(n);
	for (int &i : a)
		cin >> i;

	int mn = *min_element(a.begin(), a.end());
	int mx = *max_element(a.begin(), a.end());

	if (mx == mn)
		cout << 0;
	else if (mx == a[n - 1])
		cout << 1;
	else
		cout << 2;

	return 0;
}
